package s1.s1_4.milk;

import java.io.*;
import java.util.StringTokenizer;

/*
ID: huangmingbo
LANG: JAVA
TASK: milk
*/
public class milk {

    public static void main(String[] args) throws IOException {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(milk.class.getResourceAsStream(milk.class.getSimpleName() + ".in")));
                PrintWriter writer = new PrintWriter(new FileWriter(milk.class.getSimpleName() + ".out"));
        ) {

            //N M
            StringTokenizer stringTokenizer = new StringTokenizer(reader.readLine());
            int N = Integer.parseInt(stringTokenizer.nextToken());
            int M = Integer.parseInt(stringTokenizer.nextToken());
            product[] products = new product[M];

            for (int i = 0; i < M; i++) {
                stringTokenizer = new StringTokenizer(reader.readLine());
                products[i] = new product();
                products[i].price = Integer.parseInt(stringTokenizer.nextToken());
                products[i].amount = Integer.parseInt(stringTokenizer.nextToken());
            }

            qsort(products, 0, products.length - 1);
            int totalPrice = 0;
            for (int i = 0; i < M; i++) {
                if (N <= products[i].amount) {
                    totalPrice += N * products[i].price;
                    writer.println(totalPrice);
                    return;
                }

                totalPrice += products[i].price * products[i].amount;
                N -= products[i].amount;
            }

            writer.println(totalPrice);
        }
    }

    private static void qsort(product[] products, int startIndex, int endIndex) {
        if (endIndex <= startIndex) {
            return;
        }

        if ((endIndex == startIndex + 1) && (products[startIndex].price > products[endIndex].price)) {
            swap(products, startIndex, endIndex);
            return;
        }

        product base = products[startIndex];
        int i = startIndex + 1, j = endIndex;
        for (; i < j; ) {
            while (products[i].price <= base.price && i < j) {
                i++;
            }

            while (products[j].price > base.price && i < j) {
                j--;
            }

            if (i < j) {
                swap(products, i, j);

                if (i + 1 == j) {
                    break;
                }

                i++;
                j--;
            }
        }

        if (base.price >= products[i].price) {
            swap(products, startIndex, i);
        } else {
            swap(products, startIndex, i-1);
        }

        qsort(products, startIndex, i - 1);
        qsort(products, i + 1, endIndex);
    }

    static void swap(product[] products, int i, int j) {
        if (i == j) {
            return;
        }
        product tmp = products[j];
        products[j] = products[i];
        products[i] = tmp;
    }


    private static class product {
        int price;
        int amount;

    }
}
